package cn.ittgh.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {


	private static final int maxTimes = 12;

	private static final String key = "zbLwYaBUvu7J09TGHQq2=5=";

	// 获取业务数据，生成token
	public static String getToken(Map<String, Object> claims) {
		return JWT.create().withClaim("claims", claims).withExpiresAt(new Date(System.currentTimeMillis() + 1000L * 60 * 60 * maxTimes)).sign(Algorithm.HMAC256(key));
	}

	//接受token，验证token
	public static Map<String, Object> parseToken(String token) {
		return JWT.require(Algorithm.HMAC256(key)).build().verify(token).getClaim("claims").asMap();
	}
}
